<?php

jimport('joomla.application.component.controller');

class bgController extends JController {
    public function __construct(){
        parent::__construct();
        
        
        $this->model = $this->getModel();
        $this->aut = new bgAuthorize();
        
    }
    
    public function display($cachable = false, $urlparams = false) {
        parent::display($cachable, $urlparams);
        
    }
    /**
     * save temp ACTT 
    **/
    public function savetemp(){
        /* get data from submit form */
        $data = &JRequest::getVar('jform');
        $action = JRequest::getVar('action');
        if($action == "new"){
            $data['ACTT_CODE'] = HelperBG::getIDAuto('actt','ACTT_CODE');
            $addNew = true;
        }else{
            $addNew = false;
        }
        // GET data        
        $data['ACTT_DATE'] = date('Y-m-d H:i:s');     
        $data['ACTT_WEBF'] = 0;
        $data['ACTT_FLAG'] = 1;
        $data['ACTT_DBSY'] = 0;
        $data['ACTT_USER_CREATE'] = $this->aut->getUserID();
        
        
        
        //Check null or 0 for Money
        $data['ACTT_NUMBER_OF_PARTICIPANTS'] = $data['ACTT_NUMBER_OF_PARTICIPANTS']==='' ? 'null' : $data['ACTT_NUMBER_OF_PARTICIPANTS'];
        $data['ACTT_ENTRY_FEE'] = $data['ACTT_ENTRY_FEE']==='' ? 'null' : $data['ACTT_ENTRY_FEE'];
        $data['ACTT_TOTAL_PROJECT_COST'] = $data['ACTT_TOTAL_PROJECT_COST']==='' ? 'null' : $data['ACTT_TOTAL_PROJECT_COST'];
                
        /* checkbox MFAC */
        $list_mfac = '';
        $mfac = $this->model->getListMFAC();
        for($i = 0; $i < count($mfac); $i++){
            if(isset($data["MFAC".$mfac[$i]->MFAC_CODE])){
                $list_mfac .= ",".$data["MFAC".$mfac[$i]->MFAC_CODE];
            }    
        }
        $list_mfac = substr($list_mfac,1);
        $data['ACTT_MFAC_CODE_LIST'] = $list_mfac;
        
        /* checkbox MOBJ */
        $list_mobj = '';
        $mobj = $this->model->getListMOBJ();
        for($i = 0; $i < count($mobj); $i++){
            if(isset($data["MOBJ".$mobj[$i]->MOBJ_CODE])){
                $list_mobj .= ",".$data["MOBJ".$mobj[$i]->MOBJ_CODE];
            }    
        }
        $list_mobj = substr($list_mobj,1);
        $data['ACTT_MOBJ_CODE_LIST'] = $list_mobj;
        
        /* checkbox MCON */
        $list_mcon = '';
        $mcon = $this->model->getListMCON();
        for($i = 0; $i < count($mcon); $i++){
            if(isset($data["MCON".$mcon[$i]->MCON_CODE])){
                $list_mcon .= ",".$data["MCON".$mcon[$i]->MCON_CODE];
            }    
        }
        $list_mcon = substr($list_mcon,1);
        $data['ACTT_MCON_CODE_LIST'] = $list_mcon;
          
        /* get file */
        
        if($addNew == true){
            $data['ACTT_IMAGE_1'] = $_POST['jformACTT_IMAGE_1'];
            $data['ACTT_IMAGE_2'] = $_POST['jformACTT_IMAGE_2'];
            $data['ACTT_IMAGE_3'] = $_POST['jformACTT_IMAGE_3'];
            $data['ACTT_IMAGE_4'] = $_POST['jformACTT_IMAGE_4'];
            $data['ACTT_IMAGE_5'] = $_POST['jformACTT_IMAGE_5'];

            $data['ACTT_ATTACHMENT_1'] = $_POST['jformACTT_ATTACHMENT_1'];
            $data['ACTT_ATTACHMENT_2'] = $_POST['jformACTT_ATTACHMENT_2'];
            $data['ACTT_ATTACHMENT_3'] = $_POST['jformACTT_ATTACHMENT_3'];
            $data['ACTT_ATTACHMENT_4'] = $_POST['jformACTT_ATTACHMENT_4'];
            $data['ACTT_ATTACHMENT_5'] = $_POST['jformACTT_ATTACHMENT_5'];
            $data['ACTT_ATTACHMENT_6'] = $_POST['jformACTT_ATTACHMENT_6'];
            /* get image */
            /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_1']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_1.'.end($name);
                
                $data['ACTT_IMAGE_1'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_2']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_2.'.end($name);
                
                $data['ACTT_IMAGE_2'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_3']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_3.'.end($name);
                
                $data['ACTT_IMAGE_3'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
                
                $name = explode('.', $_FILES['jformACTT_IMAGE_4']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_4.'.end($name);
                
                $data['ACTT_IMAGE_4'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_5']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_5.'.end($name);
                
                $data['ACTT_IMAGE_5'] = $image_name;
            }
            
            
            if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                $data['ACTT_ATTACHMENT_1'] = $_FILES['jformACTT_ATTACHMENT_1']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                $data['ACTT_ATTACHMENT_2'] = $_FILES['jformACTT_ATTACHMENT_2']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                $data['ACTT_ATTACHMENT_3'] = $_FILES['jformACTT_ATTACHMENT_3']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                $data['ACTT_ATTACHMENT_4'] = $_FILES['jformACTT_ATTACHMENT_4']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                $data['ACTT_ATTACHMENT_5'] = $_FILES['jformACTT_ATTACHMENT_5']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                $data['ACTT_ATTACHMENT_6'] = $_FILES['jformACTT_ATTACHMENT_6']['name'];
            }*/
        }else{
            //* IMAGE 1 */
            /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_1']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_1.'.end($name);
                
                $data['ACTT_IMAGE_1'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_1_OLD'])){
                    $data['ACTT_IMAGE_1'] = $data['ACTT_IMAGE_1_OLD'];
                }
            }*/
           
            if(!empty($_POST['jformACTT_IMAGE_1'])){              
                $data['ACTT_IMAGE_1'] = $_POST['jformACTT_IMAGE_1'];
            }else{
                if(!empty($data['ACTT_IMAGE_1_OLD'])){
                    $data['ACTT_IMAGE_1'] = $data['ACTT_IMAGE_1_OLD'];
                }
            }



           /* if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_2']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_2.'.end($name);
                
                $data['ACTT_IMAGE_2'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_2_OLD'])){
                    $data['ACTT_IMAGE_2'] = $data['ACTT_IMAGE_2_OLD'];
                }
            }*/
           if(!empty($_POST['jformACTT_IMAGE_2'])){              
                $data['ACTT_IMAGE_2'] = $_POST['jformACTT_IMAGE_2'];
            }else{
                if(!empty($data['ACTT_IMAGE_2_OLD'])){
                    $data['ACTT_IMAGE_2'] = $data['ACTT_IMAGE_2_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_3']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_3.'.end($name);
                
                $data['ACTT_IMAGE_3'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_3_OLD'])){
                    $data['ACTT_IMAGE_3'] = $data['ACTT_IMAGE_3_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_IMAGE_3'])){              
                $data['ACTT_IMAGE_3'] = $_POST['jformACTT_IMAGE_3'];
            }else{
                if(!empty($data['ACTT_IMAGE_3_OLD'])){
                    $data['ACTT_IMAGE_3'] = $data['ACTT_IMAGE_3_OLD'];
                }
            }
           
            /*if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_4']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_4.'.end($name);
                
                $data['ACTT_IMAGE_4'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_4_OLD'])){
                    $data['ACTT_IMAGE_4'] = $data['ACTT_IMAGE_4_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_IMAGE_4'])){              
                $data['ACTT_IMAGE_4'] = $_POST['jformACTT_IMAGE_4'];
            }else{
                if(!empty($data['ACTT_IMAGE_4_OLD'])){
                    $data['ACTT_IMAGE_4'] = $data['ACTT_IMAGE_4_OLD'];
                }
            }
            
            /*if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
                
                $name = explode('.', $_FILES['jformACTT_IMAGE_5']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_5.'.end($name);
                
                $data['ACTT_IMAGE_5'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_5_OLD'])){
                    $data['ACTT_IMAGE_5'] = $data['ACTT_IMAGE_5_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_IMAGE_5'])){              
                $data['ACTT_IMAGE_5'] = $_POST['jformACTT_IMAGE_5'];
            }else{
                if(!empty($data['ACTT_IMAGE_5_OLD'])){
                    $data['ACTT_IMAGE_5'] = $data['ACTT_IMAGE_5_OLD'];
                }
            }
            
            /*if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                $data['ACTT_ATTACHMENT_1'] = $_FILES['jformACTT_ATTACHMENT_1']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_1_OLD'])){
                    $data['ACTT_ATTACHMENT_1'] = $data['ACTT_ATTACHMENT_1_OLD'];
                }
            }*/
           
            if(!empty($_POST['jformACTT_ATTACHMENT_1'])){
                
                $data['ACTT_ATTACHMENT_1'] = $_POST['jformACTT_ATTACHMENT_1'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_1_OLD'])){
                    $data['ACTT_ATTACHMENT_1'] = $data['ACTT_ATTACHMENT_1_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                $data['ACTT_ATTACHMENT_2'] = $_FILES['jformACTT_ATTACHMENT_2']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_2_OLD'])){
                    $data['ACTT_ATTACHMENT_2'] = $data['ACTT_ATTACHMENT_2_OLD'];
                }
            }*/
            
            if(!empty($_POST['jformACTT_ATTACHMENT_2'])){
                
                $data['ACTT_ATTACHMENT_2'] = $_POST['jformACTT_ATTACHMENT_2'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_2_OLD'])){
                    $data['ACTT_ATTACHMENT_2'] = $data['ACTT_ATTACHMENT_2_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                $data['ACTT_ATTACHMENT_3'] = $_FILES['jformACTT_ATTACHMENT_3']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_3_OLD'])){
                    $data['ACTT_ATTACHMENT_3'] = $data['ACTT_ATTACHMENT_3_OLD'];
                }
            }
            */
           if(!empty($_POST['jformACTT_ATTACHMENT_3'])){
                
                $data['ACTT_ATTACHMENT_3'] = $_POST['jformACTT_ATTACHMENT_3'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_3_OLD'])){
                    $data['ACTT_ATTACHMENT_3'] = $data['ACTT_ATTACHMENT_3_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                $data['ACTT_ATTACHMENT_4'] = $_FILES['jformACTT_ATTACHMENT_4']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_4_OLD'])){
                    $data['ACTT_ATTACHMENT_4'] = $data['ACTT_ATTACHMENT_4_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_ATTACHMENT_4'])){
                
                $data['ACTT_ATTACHMENT_4'] = $_POST['jformACTT_ATTACHMENT_4'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_4_OLD'])){
                    $data['ACTT_ATTACHMENT_4'] = $data['ACTT_ATTACHMENT_4_OLD'];
                }
            }



           
            /*if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                $data['ACTT_ATTACHMENT_5'] = $_FILES['jformACTT_ATTACHMENT_5']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_5_OLD'])){
                    $data['ACTT_ATTACHMENT_5'] = $data['ACTT_ATTACHMENT_5_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_ATTACHMENT_5'])){
                
                $data['ACTT_ATTACHMENT_5'] = $_POST['jformACTT_ATTACHMENT_5'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_5_OLD'])){
                    $data['ACTT_ATTACHMENT_5'] = $data['ACTT_ATTACHMENT_5_OLD'];
                }
            }
           
            /*if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                $data['ACTT_ATTACHMENT_6'] = $_FILES['jformACTT_ATTACHMENT_6']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_6_OLD'])){
                    $data['ACTT_ATTACHMENT_6'] = $data['ACTT_ATTACHMENT_6_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_ATTACHMENT_6'])){
                
                $data['ACTT_ATTACHMENT_6'] = $_POST['jformACTT_ATTACHMENT_6'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_6_OLD'])){
                    $data['ACTT_ATTACHMENT_6'] = $data['ACTT_ATTACHMENT_6_OLD'];
                }
            }
            
        }
        
        
        /**
         * check data
        **/
        if(empty($data['ACTT_NAME'])){
            $error = "名称を入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }elseif(empty($data['ACTT_OCBA_CODE'])){
            $error = "センター・クラブコードを入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }else{
            /**
             * save data
            **/
            if($this->model->save($data, $addNew)){
                if($addNew == true){
                    /* upload image */
                    /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_1']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_1']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_2']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_2']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_3']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_3']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_4']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_4']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_5']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_5']);
                    }*/
                    /* upload attachment */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                        $encodeAT1 = sha1($_FILES['jformACTT_ATTACHMENT_1']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_1']['tmp_name'],"uploads/files/com_activity/" . $encodeAT1);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                        $encodeAT2 = sha1($_FILES['jformACTT_ATTACHMENT_2']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_2']['tmp_name'],"uploads/files/com_activity/" . $encodeAT2);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                        $encodeAT3 = sha1($_FILES['jformACTT_ATTACHMENT_3']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_3']['tmp_name'],"uploads/files/com_activity/" . $encodeAT3);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                        $encodeAT4 = sha1($_FILES['jformACTT_ATTACHMENT_4']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_4']['tmp_name'],"uploads/files/com_activity/" . $encodeAT4);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                        $encodeAT5 = sha1($_FILES['jformACTT_ATTACHMENT_5']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_5']['tmp_name'],"uploads/files/com_activity/" . $encodeAT5);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                        $encodeAT6 = sha1($_FILES['jformACTT_ATTACHMENT_6']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_6']['tmp_name'],"uploads/files/com_activity/" . $encodeAT6);
                    }*/
                      
                }else{
                    /* IMAGE 1 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_1']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_1']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_1']['name'] != $data['ACTT_IMAGE_1_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_1_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_1'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_1'] != $data['ACTT_IMAGE_1_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_1_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    

                    /* IMAGE 2 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_2']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_2']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_2']['name'] != $data['ACTT_IMAGE_2_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_2_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_2'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_2'] != $data['ACTT_IMAGE_2_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_2_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }

                    /* IMAGE 3 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_3']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_3']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_3']['name'] != $data['ACTT_IMAGE_3_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_3_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_3'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_3'] != $data['ACTT_IMAGE_3_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_3_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* IMAGE 4 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_4']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_4']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_4']['name'] != $data['ACTT_IMAGE_4_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_4_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_4'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_4'] != $data['ACTT_IMAGE_4_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_4_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* IMAGE 5 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_5']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_5']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_5']['name'] != $data['ACTT_IMAGE_5_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_5_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_5'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_5'] != $data['ACTT_IMAGE_5_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_5_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    
                    /* ATTACHMENT 1 */
                   /* if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                        $encodeAT1 = sha1($_FILES['jformACTT_ATTACHMENT_1']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_1']["tmp_name"],"uploads/files/com_activity/" . $encodeAT1);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_1']['name'] != $data['ACTT_ATTACHMENT_1_OLD']){
                            $encodeAT_OLD1 = sha1($data['ACTT_ATTACHMENT_1_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD1;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_1'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_1'] != $data['ACTT_ATTACHMENT_1_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_1_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    
                    /* ATTACHMENT 2 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                        $encodeAT2 = sha1($_FILES['jformACTT_ATTACHMENT_2']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_2']["tmp_name"],"uploads/files/com_activity/" . $encodeAT2);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_2']['name'] != $data['ACTT_ATTACHMENT_2_OLD']){
                            $encodeAT_OLD2 = sha1($data['ACTT_ATTACHMENT_2_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD2;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_2'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_2'] != $data['ACTT_ATTACHMENT_2_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_2_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 3 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                        $encodeAT3 = sha1($_FILES['jformACTT_ATTACHMENT_3']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_3']["tmp_name"],"uploads/files/com_activity/" . $encodeAT3);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_3']['name'] != $data['ACTT_ATTACHMENT_3_OLD']){
                            $encodeAT_OLD3 = sha1($data['ACTT_ATTACHMENT_3_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD3;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_3'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_3'] != $data['ACTT_ATTACHMENT_3_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_3_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 4 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                        $encodeAT4 = sha1($_FILES['jformACTT_ATTACHMENT_4']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_4']["tmp_name"],"uploads/files/com_activity/" . $encodeAT4);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_4']['name'] != $data['ACTT_ATTACHMENT_4_OLD']){
                            $encodeAT_OLD4 = sha1($data['ACTT_ATTACHMENT_4_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD4;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_4'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_4'] != $data['ACTT_ATTACHMENT_4_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_4_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 5 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                        $encodeAT5 = sha1($_FILES['jformACTT_ATTACHMENT_5']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_5']["tmp_name"],"uploads/files/com_activity/" . $encodeAT5);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_5']['name'] != $data['ACTT_ATTACHMENT_5_OLD']){
                            $encodeAT_OLD5 = sha1($data['ACTT_ATTACHMENT_5_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD5;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_5'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_5'] != $data['ACTT_ATTACHMENT_5_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_5_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 6 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                        $encodeAT6 = sha1($_FILES['jformACTT_ATTACHMENT_6']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_6']["tmp_name"],"uploads/files/com_activity/" . $encodeAT6);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_6']['name'] != $data['ACTT_ATTACHMENT_6_OLD']){
                            $encodeAT_OLD6 = sha1($data['ACTT_ATTACHMENT_6_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD6;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_6'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_6'] != $data['ACTT_ATTACHMENT_6_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_6_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                }
                
                $this->setRedirect('index.php?option=com_activity');
            }else{
                $error = "エラー！データが記録されません。";
                JRequest::setVar('task','');
                JFactory::getApplication()->enqueueMessage($error, 'error');
            }
        }    
        parent::display();
    }
    
    /**
     * save ACTT 
    **/
    public function save(){
        /* get data from submit form */
        $data = &JRequest::getVar('jform');
        $action = JRequest::getVar('action');
        if($action == "new"){
            $data['ACTT_CODE'] = HelperBG::getIDAuto('actt','ACTT_CODE');
            $addNew = true;
        }else{
            $addNew = false;
        }
        // GET data        
        $data['ACTT_DATE'] = date('Y-m-d H:i:s');     
        $data['ACTT_WEBF'] = 1;
        $data['ACTT_FLAG'] = 1;
        $data['ACTT_DBSY'] = 0;
        $data['ACTT_USER_CREATE'] = $this->aut->getUserID();
        
        
        //Check null or 0 for Money
        $data['ACTT_NUMBER_OF_PARTICIPANTS'] = $data['ACTT_NUMBER_OF_PARTICIPANTS']==='' ? 'null' : $data['ACTT_NUMBER_OF_PARTICIPANTS'];
        $data['ACTT_ENTRY_FEE'] = $data['ACTT_ENTRY_FEE']==='' ? 'null' : $data['ACTT_ENTRY_FEE'];
        $data['ACTT_TOTAL_PROJECT_COST'] = $data['ACTT_TOTAL_PROJECT_COST']==='' ? 'null' : $data['ACTT_TOTAL_PROJECT_COST'];
                
        /* checkbox MFAC */
        $list_mfac = '';
        $mfac = $this->model->getListMFAC();
        for($i = 0; $i < count($mfac); $i++){
            if(isset($data["MFAC".$mfac[$i]->MFAC_CODE])){
                $list_mfac .= ",".$data["MFAC".$mfac[$i]->MFAC_CODE];
            }    
        }
        $list_mfac = substr($list_mfac,1);
        $data['ACTT_MFAC_CODE_LIST'] = $list_mfac;
        
        /* checkbox MOBJ */
        $list_mobj = '';
        $mobj = $this->model->getListMOBJ();
        for($i = 0; $i < count($mobj); $i++){
            if(isset($data["MOBJ".$mobj[$i]->MOBJ_CODE])){
                $list_mobj .= ",".$data["MOBJ".$mobj[$i]->MOBJ_CODE];
            }    
        }
        $list_mobj = substr($list_mobj,1);
        $data['ACTT_MOBJ_CODE_LIST'] = $list_mobj;
        
        /* checkbox MCON */
        $list_mcon = '';
        $mcon = $this->model->getListMCON();
        for($i = 0; $i < count($mcon); $i++){
            if(isset($data["MCON".$mcon[$i]->MCON_CODE])){
                $list_mcon .= ",".$data["MCON".$mcon[$i]->MCON_CODE];
            }    
        }
        $list_mcon = substr($list_mcon,1);
        $data['ACTT_MCON_CODE_LIST'] = $list_mcon;
          
        /* get file */
        
        if($addNew == true){
            $data['ACTT_IMAGE_1'] = $_POST['jformACTT_IMAGE_1'];
            $data['ACTT_IMAGE_2'] = $_POST['jformACTT_IMAGE_2'];
            $data['ACTT_IMAGE_3'] = $_POST['jformACTT_IMAGE_3'];
            $data['ACTT_IMAGE_4'] = $_POST['jformACTT_IMAGE_4'];
            $data['ACTT_IMAGE_5'] = $_POST['jformACTT_IMAGE_5'];

            $data['ACTT_ATTACHMENT_1'] = $_POST['jformACTT_ATTACHMENT_1'];
            $data['ACTT_ATTACHMENT_2'] = $_POST['jformACTT_ATTACHMENT_2'];
            $data['ACTT_ATTACHMENT_3'] = $_POST['jformACTT_ATTACHMENT_3'];
            $data['ACTT_ATTACHMENT_4'] = $_POST['jformACTT_ATTACHMENT_4'];
            $data['ACTT_ATTACHMENT_5'] = $_POST['jformACTT_ATTACHMENT_5'];
            $data['ACTT_ATTACHMENT_6'] = $_POST['jformACTT_ATTACHMENT_6'];
            /* get image */
            /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_1']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_1.'.end($name);
                
                $data['ACTT_IMAGE_1'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_2']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_2.'.end($name);
                
                $data['ACTT_IMAGE_2'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_3']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_3.'.end($name);
                
                $data['ACTT_IMAGE_3'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
                
                $name = explode('.', $_FILES['jformACTT_IMAGE_4']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_4.'.end($name);
                
                $data['ACTT_IMAGE_4'] = $image_name;
            }
            if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_5']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_5.'.end($name);
                
                $data['ACTT_IMAGE_5'] = $image_name;
            }
            
            
            if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                $data['ACTT_ATTACHMENT_1'] = $_FILES['jformACTT_ATTACHMENT_1']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                $data['ACTT_ATTACHMENT_2'] = $_FILES['jformACTT_ATTACHMENT_2']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                $data['ACTT_ATTACHMENT_3'] = $_FILES['jformACTT_ATTACHMENT_3']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                $data['ACTT_ATTACHMENT_4'] = $_FILES['jformACTT_ATTACHMENT_4']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                $data['ACTT_ATTACHMENT_5'] = $_FILES['jformACTT_ATTACHMENT_5']['name'];
            }
            if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                $data['ACTT_ATTACHMENT_6'] = $_FILES['jformACTT_ATTACHMENT_6']['name'];
            }*/
        }else{
            //* IMAGE 1 */
            /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_1']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_1.'.end($name);
                
                $data['ACTT_IMAGE_1'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_1_OLD'])){
                    $data['ACTT_IMAGE_1'] = $data['ACTT_IMAGE_1_OLD'];
                }
            }*/
           
            if(!empty($_POST['jformACTT_IMAGE_1'])){              
                $data['ACTT_IMAGE_1'] = $_POST['jformACTT_IMAGE_1'];
            }else{
                if(!empty($data['ACTT_IMAGE_1_OLD'])){
                    $data['ACTT_IMAGE_1'] = $data['ACTT_IMAGE_1_OLD'];
                }
            }



           /* if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_2']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_2.'.end($name);
                
                $data['ACTT_IMAGE_2'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_2_OLD'])){
                    $data['ACTT_IMAGE_2'] = $data['ACTT_IMAGE_2_OLD'];
                }
            }*/
           if(!empty($_POST['jformACTT_IMAGE_2'])){              
                $data['ACTT_IMAGE_2'] = $_POST['jformACTT_IMAGE_2'];
            }else{
                if(!empty($data['ACTT_IMAGE_2_OLD'])){
                    $data['ACTT_IMAGE_2'] = $data['ACTT_IMAGE_2_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_3']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_3.'.end($name);
                
                $data['ACTT_IMAGE_3'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_3_OLD'])){
                    $data['ACTT_IMAGE_3'] = $data['ACTT_IMAGE_3_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_IMAGE_3'])){              
                $data['ACTT_IMAGE_3'] = $_POST['jformACTT_IMAGE_3'];
            }else{
                if(!empty($data['ACTT_IMAGE_3_OLD'])){
                    $data['ACTT_IMAGE_3'] = $data['ACTT_IMAGE_3_OLD'];
                }
            }
           
            /*if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
               
                $name = explode('.', $_FILES['jformACTT_IMAGE_4']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_4.'.end($name);
                
                $data['ACTT_IMAGE_4'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_4_OLD'])){
                    $data['ACTT_IMAGE_4'] = $data['ACTT_IMAGE_4_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_IMAGE_4'])){              
                $data['ACTT_IMAGE_4'] = $_POST['jformACTT_IMAGE_4'];
            }else{
                if(!empty($data['ACTT_IMAGE_4_OLD'])){
                    $data['ACTT_IMAGE_4'] = $data['ACTT_IMAGE_4_OLD'];
                }
            }
            
            /*if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
                
                $name = explode('.', $_FILES['jformACTT_IMAGE_5']['name']);
                $image_name = 'ac'.$data['ACTT_CODE'].'_'.date("Y-m-d_H-i",time()).'_5.'.end($name);
                
                $data['ACTT_IMAGE_5'] = $image_name;
            }else{
                if(!empty($data['ACTT_IMAGE_5_OLD'])){
                    $data['ACTT_IMAGE_5'] = $data['ACTT_IMAGE_5_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_IMAGE_5'])){              
                $data['ACTT_IMAGE_5'] = $_POST['jformACTT_IMAGE_5'];
            }else{
                if(!empty($data['ACTT_IMAGE_5_OLD'])){
                    $data['ACTT_IMAGE_5'] = $data['ACTT_IMAGE_5_OLD'];
                }
            }
            
            /*if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                $data['ACTT_ATTACHMENT_1'] = $_FILES['jformACTT_ATTACHMENT_1']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_1_OLD'])){
                    $data['ACTT_ATTACHMENT_1'] = $data['ACTT_ATTACHMENT_1_OLD'];
                }
            }*/
           
            if(!empty($_POST['jformACTT_ATTACHMENT_1'])){
                
                $data['ACTT_ATTACHMENT_1'] = $_POST['jformACTT_ATTACHMENT_1'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_1_OLD'])){
                    $data['ACTT_ATTACHMENT_1'] = $data['ACTT_ATTACHMENT_1_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                $data['ACTT_ATTACHMENT_2'] = $_FILES['jformACTT_ATTACHMENT_2']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_2_OLD'])){
                    $data['ACTT_ATTACHMENT_2'] = $data['ACTT_ATTACHMENT_2_OLD'];
                }
            }*/
            
            if(!empty($_POST['jformACTT_ATTACHMENT_2'])){
                
                $data['ACTT_ATTACHMENT_2'] = $_POST['jformACTT_ATTACHMENT_2'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_2_OLD'])){
                    $data['ACTT_ATTACHMENT_2'] = $data['ACTT_ATTACHMENT_2_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                $data['ACTT_ATTACHMENT_3'] = $_FILES['jformACTT_ATTACHMENT_3']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_3_OLD'])){
                    $data['ACTT_ATTACHMENT_3'] = $data['ACTT_ATTACHMENT_3_OLD'];
                }
            }
            */
           if(!empty($_POST['jformACTT_ATTACHMENT_3'])){
                
                $data['ACTT_ATTACHMENT_3'] = $_POST['jformACTT_ATTACHMENT_3'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_3_OLD'])){
                    $data['ACTT_ATTACHMENT_3'] = $data['ACTT_ATTACHMENT_3_OLD'];
                }
            }

            /*if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                $data['ACTT_ATTACHMENT_4'] = $_FILES['jformACTT_ATTACHMENT_4']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_4_OLD'])){
                    $data['ACTT_ATTACHMENT_4'] = $data['ACTT_ATTACHMENT_4_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_ATTACHMENT_4'])){
                
                $data['ACTT_ATTACHMENT_4'] = $_POST['jformACTT_ATTACHMENT_4'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_4_OLD'])){
                    $data['ACTT_ATTACHMENT_4'] = $data['ACTT_ATTACHMENT_4_OLD'];
                }
            }



           
            /*if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                $data['ACTT_ATTACHMENT_5'] = $_FILES['jformACTT_ATTACHMENT_5']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_5_OLD'])){
                    $data['ACTT_ATTACHMENT_5'] = $data['ACTT_ATTACHMENT_5_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_ATTACHMENT_5'])){
                
                $data['ACTT_ATTACHMENT_5'] = $_POST['jformACTT_ATTACHMENT_5'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_5_OLD'])){
                    $data['ACTT_ATTACHMENT_5'] = $data['ACTT_ATTACHMENT_5_OLD'];
                }
            }
           
            /*if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                $data['ACTT_ATTACHMENT_6'] = $_FILES['jformACTT_ATTACHMENT_6']['name'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_6_OLD'])){
                    $data['ACTT_ATTACHMENT_6'] = $data['ACTT_ATTACHMENT_6_OLD'];
                }
            }*/
            if(!empty($_POST['jformACTT_ATTACHMENT_6'])){
                
                $data['ACTT_ATTACHMENT_6'] = $_POST['jformACTT_ATTACHMENT_6'];
            }else{
                if(!empty($data['ACTT_ATTACHMENT_6_OLD'])){
                    $data['ACTT_ATTACHMENT_6'] = $data['ACTT_ATTACHMENT_6_OLD'];
                }
            }
            
        }
        
        
        /**
         * check data
        **/
        if(empty($data['ACTT_NAME'])){
            $error = "名称を入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }elseif(empty($data['ACTT_OCBA_CODE'])){
            $error = "センター・クラブコードを入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }else{
            /**
             * save data
            **/
            if($this->model->save($data, $addNew)){
                if($addNew == true){
                    /* upload image */
                    /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_1']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_1']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_2']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_2']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_3']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_3']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_4']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_4']);
                    }
                    if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_5']['tmp_name'],"uploads/images/com_activity/" . $data['ACTT_IMAGE_5']);
                    }*/
                    /* upload attachment */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                        $encodeAT1 = sha1($_FILES['jformACTT_ATTACHMENT_1']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_1']['tmp_name'],"uploads/files/com_activity/" . $encodeAT1);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                        $encodeAT2 = sha1($_FILES['jformACTT_ATTACHMENT_2']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_2']['tmp_name'],"uploads/files/com_activity/" . $encodeAT2);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                        $encodeAT3 = sha1($_FILES['jformACTT_ATTACHMENT_3']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_3']['tmp_name'],"uploads/files/com_activity/" . $encodeAT3);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                        $encodeAT4 = sha1($_FILES['jformACTT_ATTACHMENT_4']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_4']['tmp_name'],"uploads/files/com_activity/" . $encodeAT4);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                        $encodeAT5 = sha1($_FILES['jformACTT_ATTACHMENT_5']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_5']['tmp_name'],"uploads/files/com_activity/" . $encodeAT5);
                    }
                    if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                        $encodeAT6 = sha1($_FILES['jformACTT_ATTACHMENT_6']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_6']['tmp_name'],"uploads/files/com_activity/" . $encodeAT6);
                    }*/
                      
                }else{
                    /* IMAGE 1 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_1']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_1']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_1']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_1']['name'] != $data['ACTT_IMAGE_1_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_1_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_1'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_1'] != $data['ACTT_IMAGE_1_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_1_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    

                    /* IMAGE 2 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_2']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_2']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_2']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_2']['name'] != $data['ACTT_IMAGE_2_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_2_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_2'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_2'] != $data['ACTT_IMAGE_2_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_2_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }

                    /* IMAGE 3 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_3']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_3']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_3']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_3']['name'] != $data['ACTT_IMAGE_3_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_3_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_3'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_3'] != $data['ACTT_IMAGE_3_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_3_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* IMAGE 4 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_4']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_4']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_4']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_4']['name'] != $data['ACTT_IMAGE_4_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_4_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_4'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_4'] != $data['ACTT_IMAGE_4_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_4_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* IMAGE 5 */
                    /*if(!empty($_FILES['jformACTT_IMAGE_5']['name'])){
                        move_uploaded_file($_FILES['jformACTT_IMAGE_5']["tmp_name"],"uploads/images/com_activity/" . $data['ACTT_IMAGE_5']);
                        //del old file
                        if($_FILES['jformACTT_IMAGE_5']['name'] != $data['ACTT_IMAGE_5_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_5_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_IMAGE_5'])){                        
                        //del old file
                        if($_POST['jformACTT_IMAGE_5'] != $data['ACTT_IMAGE_5_OLD']){
                            $path = "uploads/images/com_activity/".$data['ACTT_IMAGE_5_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    
                    /* ATTACHMENT 1 */
                   /* if(!empty($_FILES['jformACTT_ATTACHMENT_1']['name'])){
                        $encodeAT1 = sha1($_FILES['jformACTT_ATTACHMENT_1']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_1']["tmp_name"],"uploads/files/com_activity/" . $encodeAT1);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_1']['name'] != $data['ACTT_ATTACHMENT_1_OLD']){
                            $encodeAT_OLD1 = sha1($data['ACTT_ATTACHMENT_1_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD1;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_1'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_1'] != $data['ACTT_ATTACHMENT_1_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_1_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    
                    /* ATTACHMENT 2 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_2']['name'])){
                        $encodeAT2 = sha1($_FILES['jformACTT_ATTACHMENT_2']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_2']["tmp_name"],"uploads/files/com_activity/" . $encodeAT2);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_2']['name'] != $data['ACTT_ATTACHMENT_2_OLD']){
                            $encodeAT_OLD2 = sha1($data['ACTT_ATTACHMENT_2_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD2;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_2'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_2'] != $data['ACTT_ATTACHMENT_2_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_2_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 3 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_3']['name'])){
                        $encodeAT3 = sha1($_FILES['jformACTT_ATTACHMENT_3']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_3']["tmp_name"],"uploads/files/com_activity/" . $encodeAT3);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_3']['name'] != $data['ACTT_ATTACHMENT_3_OLD']){
                            $encodeAT_OLD3 = sha1($data['ACTT_ATTACHMENT_3_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD3;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_3'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_3'] != $data['ACTT_ATTACHMENT_3_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_3_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 4 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_4']['name'])){
                        $encodeAT4 = sha1($_FILES['jformACTT_ATTACHMENT_4']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_4']["tmp_name"],"uploads/files/com_activity/" . $encodeAT4);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_4']['name'] != $data['ACTT_ATTACHMENT_4_OLD']){
                            $encodeAT_OLD4 = sha1($data['ACTT_ATTACHMENT_4_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD4;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_4'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_4'] != $data['ACTT_ATTACHMENT_4_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_4_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 5 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_5']['name'])){
                        $encodeAT5 = sha1($_FILES['jformACTT_ATTACHMENT_5']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_5']["tmp_name"],"uploads/files/com_activity/" . $encodeAT5);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_5']['name'] != $data['ACTT_ATTACHMENT_5_OLD']){
                            $encodeAT_OLD5 = sha1($data['ACTT_ATTACHMENT_5_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD5;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_5'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_5'] != $data['ACTT_ATTACHMENT_5_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_5_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                    /* ATTACHMENT 6 */
                    /*if(!empty($_FILES['jformACTT_ATTACHMENT_6']['name'])){
                        $encodeAT6 = sha1($_FILES['jformACTT_ATTACHMENT_6']['name']);
                        move_uploaded_file($_FILES['jformACTT_ATTACHMENT_6']["tmp_name"],"uploads/files/com_activity/" . $encodeAT6);
                        //del old file
                        if($_FILES['jformACTT_ATTACHMENT_6']['name'] != $data['ACTT_ATTACHMENT_6_OLD']){
                            $encodeAT_OLD6 = sha1($data['ACTT_ATTACHMENT_6_OLD']);
                            $path = "uploads/images/com_activity/".$encodeAT_OLD6;
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }*/
                    if(!empty($_POST['jformACTT_ATTACHMENT_6'])){
                        //del old file
                        if($_POST['jformACTT_ATTACHMENT_6'] != $data['ACTT_ATTACHMENT_6_OLD']){                            
                            $path = "uploads/files/com_activity/".$data['ACTT_ATTACHMENT_6_OLD'];
                            if(file_exists($path)){ 
                                $del = unlink($path);
                            }
                        }
                    }
                }
                
                $this->setRedirect('index.php?option=com_activity');
            }else{
                $error = "エラー！データが記録されません。";
                JRequest::setVar('task','');
                JFactory::getApplication()->enqueueMessage($error, 'error');
            }
        }
        parent::display();
    }
    
    /**
     * Delete list ACTT selected
    **/
    public function remove(){
   	    $cid = JRequest::getVar('cid');
        
        /* remove imaage in server */
        foreach($cid as $value){
            //get image name
            $file = $this->getModel()->getFileNameFromACTT_CODE($value);
            //Del Image
            if($file != null){
                //IMAGE 1
                if($file->ACTT_IMAGE_1 != null){                    
                    $path = "uploads/images/com_activity/$file->ACTT_IMAGE_1";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //IMAGE 2
                if($file->ACTT_IMAGE_2 != null){
                    $path = "uploads/images/com_activity/$file->ACTT_IMAGE_2";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //IMAGE 3
                if($file->ACTT_IMAGE_3 != null){
                    $path = "uploads/images/com_activity/$file->ACTT_IMAGE_3";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //IMAGE 4
                if($file->ACTT_IMAGE_4 != null){
                    $path = "uploads/images/com_activity/$file->ACTT_IMAGE_4";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //IMAGE 5
                if($file->ACTT_IMAGE_5 != null){
                    $path = "uploads/images/com_activity/$file->ACTT_IMAGE_5";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                
                //ATTACHMENT 1
                if($file->ACTT_ATTACHMENT_1 != null){
                    $encodeFILE1 = sha1($file->ACTT_ATTACHMENT_1);
                    $path = "uploads/files/com_activity/$encodeFILE1";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //ATTACHMENT 2
                if($file->ACTT_ATTACHMENT_2 != null){
                    $encodeFILE2 = sha1($file->ACTT_ATTACHMENT_2);
                    $path = "uploads/files/com_activity/$encodeFILE2";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //ATTACHMENT 3
                if($file->ACTT_ATTACHMENT_3 != null){
                    $encodeFILE3 = sha1($file->ACTT_ATTACHMENT_3);
                    $path = "uploads/files/com_activity/$encodeFILE3";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //ATTACHMENT 4
                if($file->ACTT_ATTACHMENT_4 != null){
                    $encodeFILE4 = sha1($file->ACTT_ATTACHMENT_4);
                    $path = "uploads/files/com_activity/$encodeFILE4";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //ATTACHMENT 5
                if($file->ACTT_ATTACHMENT_5 != null){
                    $encodeFILE5 = sha1($file->ACTT_ATTACHMENT_5);
                    $path = "uploads/files/com_activity/$encodeFILE5";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
                //ATTACHMENT 6
                if($file->ACTT_ATTACHMENT_6 != null){
                    $encodeFILE6 = sha1($file->ACTT_ATTACHMENT_6);
                    $path = "uploads/files/com_activity/$encodeFILE6";
                    if(file_exists($path)){
                        $del = unlink($path);
                    }
                }
            }
        }
        
        $this->model->remove($cid);
        $this->setRedirect('index.php?option=com_activity');     
    }
    
    /**
	*export data from mysql (table ACTT) to file csv
	*/
    public function export_csv(){
        if(HelperBG::export_csv_actt()){
            $this->setRedirect('index.php?option=com_activity');
        }
        else{
            //JError::raiseError(500, 'Error ! Can\t export file CSV');
            $error = "エラー！CSVファイルが出力されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }
        parent::display();
    }
    
    /**
	*export data from mysql (table ACTT) to file csv
	*/
    public function export_csv_cc(){
        if(HelperBG::export_csv_actt($this->aut->getOCBA_CODE())){
            $this->setRedirect('index.php?option=com_activity');
        }
        else{
            //JError::raiseError(500, 'Error ! Can\t export file CSV');
            $error = "エラー！CSVファイルが出力されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }
        parent::display();
    }
    
    /**
	*Dong bo data from mysql (table ACTT) to file csv
	*/
    public function dongbo_csv_actt(){
        if(HelperBG::dongbo_csv_actt()){
            $this->setRedirect('index.php?option=com_activity');
        }
        else{
            //JError::raiseError(500, 'Error ! Can\t export file CSV');
            $error = "エラー！CSVファイルが出力されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }
        parent::display();
    }
    
    /**
     * Search ocba in popup
    **/
    public function searchOcba(){
        $search_name =  JRequest::getVar('search_name');
        $this->search_name = $search_name;
        $result = $this->getModel()->getListOcba($search_name);
        
        echo '
                <div class="the_scroll">
            <table class="adminlist">
        		<thead>
        			<tr>
        				<th class="th30">
        					番号	
                        </th>
                        <th class="th70">
                            名称
                        </th>
        			</tr>
        		</thead>
                
        		<tbody>';
                  
                    if($result  != null){
                        foreach($result as $k=>$row){
                                  
        echo     	  '<tr class="row'.($k%2).'">';
        echo    		'<td class="center">';
        echo                '<a href="javascript:void(0,0);" onclick="document.id('."'ocba_code_temp').value='".$row->OCBA_CODE."';".'" class="link_ocba_code" id="jformOCBA_CODE">'. $row->OCBA_CODE. '</a>
                        </td>
            			<td class="center"><a href="javascript:void(0,0);" onclick="document.id('."'ocba_code_temp').value='". $row->OCBA_CODE."';".'" class="link_ocba_code" id="jformOCBA_CODE">'. $row->OCBA_NAME. '</a></td>
            		  </tr>';
                    
                        }
                    }else{
                    
        echo            '<tr>
                            <td class="center" colspan="2">データは見つかりませんでした</td>
                        </tr>';
                    
                    }
                    
                 
       echo  	'</tbody>
               
            	</table>
                <input type="hidden" name="ocba_code_temp" id="ocba_code_temp" value="" />
            </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    /* clear search center pop up */
    public function clearSearchOcba(){
        
        $result = $this->getModel()->getListOcba();
        
        echo '
                <div class="the_scroll">
            <table class="adminlist">
        		<thead>
        			<tr>
        				<th class="th30">
        					番号	
                        </th>
                        <th class="th70">
                            名称
                        </th>
        			</tr>
        		</thead>
                
        		<tbody>';
                  
                    if($result  != null){
                        foreach($result as $k=>$row){
                                  
        echo     	  '<tr class="row'.($k%2).'">';
        echo    		'<td class="center">';
        echo                '<a href="javascript:void(0,0);" onclick="document.id('."'ocba_code_temp').value='".$row->OCBA_CODE."';".'" class="link_ocba_code" id="jformOCBA_CODE">'. $row->OCBA_CODE. '</a>
                        </td>
            			<td class="center"><a href="javascript:void(0,0);" onclick="document.id('."'ocba_code_temp').value='". $row->OCBA_CODE."';".'" class="link_ocba_code" id="jformOCBA_CODE">'. $row->OCBA_NAME. '</a></td>
            		  </tr>';
                    
                        }
                    }else{
                    
        echo            '<tr>
                            <td class="center" colspan="2">データは見つかりませんでした</td>
                        </tr>';
                    
                    }
                    
                 
       echo  	'</tbody>
               
            	</table>
                <input type="hidden" name="ocba_code_temp" id="ocba_code_temp" value="" />
            </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }

}